#include <iostream>
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <string>
using namespace std;

bool get_number ( int& number )
{
  while ( !( cin>> number ) ) {
    if ( cin.eof() )
      return false;
    else {
      char ch;
      cin.clear();
      cout<<"Please enter a number: ";
      while ( cin.get ( ch ) && ch != '\n' )
	;
    }
  }
  
  return true;
}

int main ()
{
  int left, right, sum;
  int rightnum=0;
  int calculate;
  string answers[11];
  string mark;
  char aLine[256];
  /* initialize random seed: */
  srand ( time(NULL) );
  
  int add=0, total=0;
  
  while(total<10){
    left = rand() % 13;
    right = rand() % 13;
    sum=left*right;
    if(sum<=122 && left!=0) {
      total++;
      if(add==0) {
	sprintf(aLine, " %2d * %2d = ", left, right);
	cout << aLine;
	get_number(calculate);
	if(calculate==sum) { mark=string("right!"); rightnum++;}
	else mark=string("??????wrong??????");
	sprintf(aLine, " %2d * %2d = %2d : %s", left, right, calculate, mark.c_str());
	answers[total]=string(aLine);
	add=(1+add)%2;
      } else {
	sprintf(aLine, " %2d / %2d = ", sum, left);
	cout << aLine;
	get_number(calculate);
        if(calculate==right) { mark=string("right!"); rightnum++;}
        else mark=string("??????wrong!??????");
        sprintf(aLine, " %2d / %2d = %2d : %s", sum, left, calculate, mark.c_str());
	answers[total]=string(aLine);
	add=(1+add)%2;
      }
    }
  }
  cout << endl << endl;
  for(int ii=1; ii<=10; ii++) cout << answers[ii] << endl;
  cout << endl << "Right rate:\t" << rightnum*10 << "%" << endl;
  return 0;
}
